#ifndef GNFINDPATHTHREAD_H
#define GNFINDPATHTHREAD_H

#include "dbquerybasethread.h"
#include <QReadWriteLock>
#include "serverclientsocketproc.h"

enum FilesInfoStatus{
    FINISH_PATH = 1,
    FINISH_SAVETODB = 1 << 1,
    FINISH_ALL = FINISH_PATH | FINISH_SAVETODB
};

struct PathFilesInfo
{
    QString _files;
    uint32_t _status;
};

typedef QMap<QString, PathFilesInfo> PathFilesInfoMap;

class GnFindPathThread : public DbQueryBaseThread {
    Q_OBJECT
private:
    QReadWriteLock _readWriteLock;
    PathFilesInfoMap _filterFilePaths;
    QSet<ServerClientSocketProc*> _sockets;
    bool _start = false;
public:
    inline void start()
    {
        _start = true;
    }
    inline bool getStart()
    {
        return _start;
    }
    inline QReadWriteLock& getReadWriteLock()
    {
        return _readWriteLock;
    }
    inline PathFilesInfoMap& getFilterFilePaths()
    {
        return _filterFilePaths;
    }
    inline void pushSocket(ServerClientSocketProc* p)
    {
        _sockets.insert(p);
    }
    inline const QSet<ServerClientSocketProc*>& getSocket()
    {
        return _sockets;
    }
    inline void removeSocket(ServerClientSocketProc* p)
    {
        _sockets.remove(p);
    }
    Q_INVOKABLE GnFindPathThread();
    virtual ~GnFindPathThread() override;
};

CNS_COM_DECL_METATYPE(GnFindPathThread)

class SysGnFindPathThread : public QObject
{
    Q_OBJECT
public:
    Q_INVOKABLE SysGnFindPathThread();

    void getFilterFile(GnFindPathThread* filterFilePaths, QString path, QString relativePath, const QString &filter);

    Q_INVOKABLE void f_initDbQueryThread(CnsComponentPtr com, QVariantHash& props, QScopedPointer<QThread>& thread);
    GnFindPathThreadPtr* newQueryThread(CnsComponentPtr com, QVariantHash& sv);

public slots:
    void stop(CnsComponentPtr com);
    bool f_query(CnsComponentPtr com, QString &dbID, QVariantHash &props);
};

Q_DECLARE_METATYPE(SysGnFindPathThread*)

#endif // GNFINDPATHTHREAD_H
